package com.itheima.web.controller.oss;


import com.itheima.service.oss.OssService;
import com.itheima.utils.ResultData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

@RestController
@RequestMapping("/aliyun")
public class OssController {

    @Autowired
    private OssService ossService;

    @PostMapping("/oss/upload")
    public ResultData ossUpload(MultipartFile photoFile) throws IOException {
        if (photoFile == null){
            return ResultData.error("上传有误");
        }
        String url = ossService.ossUpload(photoFile);
        Map imageUrl = new HashMap();
        imageUrl.put("url",url);

        return ResultData.ok("操作成功",imageUrl);
    }
}
